package com.ibm.tivoli.swat.tsam_ec2.tsam;

import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.GregorianCalendar;

import javax.xml.datatype.DatatypeConfigurationException;
import javax.xml.datatype.DatatypeFactory;
import javax.xml.datatype.XMLGregorianCalendar;

public class DateUtil {
	// Sample input 2011-03-31T13:35:07-04:00
	public static XMLGregorianCalendar convertDate(String string)
			throws ParseException, DatatypeConfigurationException {
		string = string.substring(0, string.length() - 6);
		SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd'T'hh:mm:ss");
		Date date = format.parse(string);
		GregorianCalendar calendar = new GregorianCalendar();
		calendar.setTime(date);
		XMLGregorianCalendar result = DatatypeFactory.newInstance()
				.newXMLGregorianCalendar(calendar);
		return result;
	}
	
	public static String getTargetStart() {
		DateFormat format = new SimpleDateFormat("yyyy-MM-dd'T'hh:mm:ssZ");
		String date = format.format(new Date());
		return date.substring(0, date.length()-2)+":"+date.substring(date.length()-2);
	}


}
